﻿Imports System.IO

Public Class FrmSplash

    Dim fileLoc As String = Application.StartupPath & "\error.log"

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label3.Text = "v.: " & Application.ProductVersion
        Me.TransparencyKey = System.Drawing.SystemColors.Desktop
        Me.BackColor = System.Drawing.SystemColors.Desktop

        Timer1.Enabled = True

        Me.Top = Screen.PrimaryScreen.WorkingArea.Height / 2 - Me.Height / 2
        Me.Left = Screen.PrimaryScreen.WorkingArea.Width / 2 - Me.Width / 2
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        '   On Error Resume Next
        On Error GoTo errH
        ''  FrmMessageBox.Show()

        Form1.Show()
        Timer1.Enabled = False
        Me.Close()
        Exit Sub
errH:

        Timer1.Enabled = False
        If Err.Number = 54 Then 'Err.Number = 5 Or
            'Dim ss = MsgBox(vbNewLine & "It seems that additional components are missing or are invalid." & vbNewLine _
            '   & "Please ensure that Interop.WMPLib.dll, AxInterop.WMPLib.dll and UNOLibs.Net.dll are located in the program directory. (This is:" & Application.StartupPath & ")." & vbNewLine & vbNewLine & "Would you like to save an error report for this?", MsgBoxStyle.YesNo, "Error loading XtreMP3 " & Application.ProductVersion)
            'If ss = vbYes Then
            FrmMessageBox.Label1.Text = "Error loading XtreMP3 " & Application.ProductVersion
            FrmMessageBox.Label2.Text = "It seems that additional components are missing or are invalid. " & "Please ensure that Interop.WMPLib.dll, AxInterop.WMPLib.dll and UNOLibs.Net.dll are located in program directory." & vbNewLine & "Program path is: " & Application.StartupPath
            Me.Hide()


            If File.Exists(fileLoc) Then

                Using sw As StreamWriter = New StreamWriter(fileLoc)
                    sw.Write(DateTime.Now & vbNewLine & Application.ProductVersion & vbNewLine & "Error: " & Err.Description & vbNewLine & "Error number: " & Err.Number & vbNewLine & vbNewLine & "Please inform the creator: info@eserver.gr")
                End Using
            Else
                Dim fs As FileStream = Nothing
                If (Not File.Exists(fileLoc)) Then
                    fs = File.Create(fileLoc)
                    Using fs

                    End Using
                End If
                Using sw As StreamWriter = New StreamWriter(fileLoc)
                    sw.Write(DateTime.Now & vbNewLine & Application.ProductVersion & vbNewLine & "Error: " & Err.Description & vbNewLine & "Error number: " & Err.Number & vbNewLine & vbNewLine & "Please inform the creator: info@eserver.gr")
                End Using
            End If
            'Else
            FrmMessageBox.ShowDialog()
            'End If
            Me.Close()
        Else
            'MsgBox("Error " & Err.Description _
            '               & vbNewLine & "Error number " & Err.Number & vbNewLine & vbNewLine & "Please inform the creator: info@eserver.gr", , "Error loading XtreMP3 " & Application.ProductVersion)
            FrmMessageBox.Label1.Text = "General error loading XtreMP3 " & Application.ProductVersion
            FrmMessageBox.Label2.Text = Err.Description _
                        & vbNewLine & "Error number: " & Err.Number & vbNewLine & vbNewLine & "Please inform the creator: info@eserver.gr"
            Me.Hide()



            If File.Exists(fileLoc) Then
                Using sw As StreamWriter = New StreamWriter(fileLoc)
                    sw.Write(DateTime.Now & vbNewLine & Application.ProductVersion & vbNewLine & "Error: " & Err.Description & vbNewLine & "Error number: " & Err.Number & vbNewLine & vbNewLine & "Please inform the creator: info@eserver.gr")
                End Using
            Else
                Dim fs As FileStream = Nothing
                If (Not File.Exists(fileLoc)) Then
                    fs = File.Create(fileLoc)
                    Using fs
                    End Using
                End If
                Using sw As StreamWriter = New StreamWriter(fileLoc)
                    sw.Write(DateTime.Now & vbNewLine & Application.ProductVersion & vbNewLine & "Error: " & Err.Description & vbNewLine & "Error number: " & Err.Number & vbNewLine & vbNewLine & "Please inform the creator: info@eserver.gr")
                End Using
            End If

            Me.Close()
        End If
        FrmMessageBox.ShowDialog()
        'Debug.Print(Err.Description)
        Exit Sub
    End Sub

    
    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click

    End Sub
End Class